<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AlterAddCreatedUid extends Migration
{

    public function addField(Blueprint $table)
    {
        $table->unsignedInteger('createdByUid')->comment('创建人')->default(0);
        $table->unsignedInteger('updatedByUid')->comment('修改人')->default(0);
    }

    public function rollbackField(Blueprint $table)
    {
        $table->dropColumn('createdByUid');
        $table->dropColumn('updatedByUid');
    }

    public $tableList =
        [
            'brands', 'category', 'config', 'menus',
            'permissions', 'product_menus', 'products',
            'roles', 'shop_product_status', 'shops',
            'user_role_mappings', 'users',
            'role_permission_mappings'
        ];


    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        foreach ($this->tableList as $table) {
            Schema::table($table, function (Blueprint $table) {
                $this->addField($table);
            });
        }

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        foreach ($this->tableList as $table) {
            Schema::table($table, function (Blueprint $table) {
                $this->rollbackField($table);
            });
        }

    }
}
